package com.apigateway.route;

/**
 * Created by 小泽玛丽罗 on 2017/2/23.
 */
public class RandomWeight {

    public static int[] weight={4,2,1};
    public static int[] current_weight={0,0,0};
    public static int[] tmp_weight={4,2,1};
    public static int total=7;


    public static void main(String[] args) {
        RandomWeight randomWeight =new RandomWeight();
        int i=0;
        while (i<14){
            System.out.print(randomWeight.next()+",");
            i++;
        }
    }
    public static int  next(){
        int maxIndex=-1;
        for(int i=0;i<tmp_weight.length;i++){
            if(maxIndex==-1)
                maxIndex=i;
            else{
                if(current_weight[i]>current_weight[maxIndex])
                    maxIndex=i;
            }
        }
        tmp_weight[maxIndex]=tmp_weight[maxIndex]-total;
        for(int i=0;i<current_weight.length;i++){
            current_weight[i]=tmp_weight[i]+weight[i];
        }
        tmp_weight=current_weight;
        return  maxIndex;
    }
}
